<template>
  <div class="container">
    <!--1、 头部 -->
    <div class="info-box">
      <van-image
        fit="cover"
        width="64px"
        height="64px"
        round
        :src="userInfo.photo"
      />
      <h2>
        {{ userInfo.name }}
        <br />
        <van-tag color="#fff" text-color="#029dfa">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <!--2、 用户也导航栏 -->
    <div class="nav-user">
      <van-row>
        <van-col span="8">
          <van-icon name="newspaper-o" color="#87c1ff" />
          <br />
          我的作品
        </van-col>
        <van-col span="8">
          <van-icon name="star-o" color="#ff2b2a" />
          <br />
          我的收藏
        </van-col>
        <van-col span="8">
          <van-icon name="tosend" color="#ffbc40" />
          <br />
          阅读历史
        </van-col>
      </van-row>
    </div>
    <!-- 3、单元格 -->
    <van-cell icon="edit" to="/edit" title="编辑资料" is-link />
    <van-cell icon="chat-o" to="/student" title="小智同学" is-link />
    <van-cell icon="setting-o" title="系统设置" is-link />
    <van-cell icon="warning-o" title="退出登录" is-link @click="exitClick" />
  </div>
</template>

<script>
name: "user";
import { getUserInfo } from "./user.js";
import { removeToken } from "@/utils/token.js";

export default {
  data() {
    return {
      userInfo: {},
    };
  },
  created() {
    // console.log(getUserInfo());
    getUserInfo()
      .then((res) => {
        console.log(res);
        this.userInfo = res.data.data;
        // console.log(this.$store.commit("updateData"));
        this.$store.commit("updateData", res.data.data);
      })
      .catch((err) => {
        console.log(err);
      });
  },
  methods: {
    exitClick() {
      //   console.log(1);
      this.$dialog
        .confirm({
          title: "退出",
          message: "您是否要退出",
        })
        .then(() => {
          //   console.log(2);
          // on confirm
          //清除token
          removeToken();
          //清除请求的数据
          this.userInfo = {};
          //跳转到首页
          this.$router.push({ path: "/" });
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>

<style  lang='less'>
.container {
  .info-box {
    height: 100px;
    display: flex;
    background-color: #029dfa;
    align-items: center;
    .van-image {
      padding: 0 15px;
    }
    h2 {
      font-size: 16px;
      font-weight: 400;
      color: #fff;
      .van-tag {
        margin-top: 5px;
      }
    }
  }
  .nav-user {
    padding: 15px 0;
    text-align: center;
    .van-col {
      font-size: 12px;
      .van-icon {
        font-size: 24px;
        margin-bottom: 5px;
      }
    }
  }
}
</style>